package dao.daoImpl;

import dao.MessageDao;
import model.Message;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: spolyakov
 * Date: 1/17/14
 * Time: 7:05 PM
 * To change this template use File | Settings | File Templates.
 */

@Repository
public class MessageDaoImpl implements MessageDao {

    @Autowired
    private SessionFactory sessionFactory;

    @Override
    public List<Message> getAll() {
        Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Message.class);
        return criteria.list();
    }

    @Override
    public void save(Message message) {
        Session session = sessionFactory.getCurrentSession();
        session.saveOrUpdate(message);
    }

}
